package com.sxt.server.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sxt.server.util.NettySession;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;


@RestController
public class MessageController {
	
	/**
	 * 	向客户端下发指令
	 * @param id
	 * @param msg
	 * @return
	 */
	@RequestMapping( method = RequestMethod.POST, value = "/sendMsg/{id}/{msg}")
    public boolean sendMsg(@PathVariable String id, @PathVariable String msg) {
        System.out.println("开始发送消息...");
        Channel channel = NettySession.get(id);
        if(channel !=null && channel.isOpen()) {
        	channel.writeAndFlush(msg);
        	//ChannelFuture rs = channel.writeAndFlush(msg);
        }
        return true;
    }
}
